home *** CD-ROM | disk | FTP | other *** search
- // filename : treeMenu.js
- // description : this js file contains functions to create a tree type
- // : menu in html
-
- Position = 0; //stores the position to place the layer
- Level=0; //stores at which level it is
- LevelPos=0; //stores the position at which the level is
- Found=false; //stores if the layer to be open is found
- imgColl = new Array(); //stores the layers which r opened
- closedImg = new Image();
- openImg = new Image();
-
-
- //this function creates a tree
- //parameters:
- // x - x pos to build the menu
- // y - y pos to build the menu
- // width - width of the layer
- //
- function TreeMenu(x,y,width)
- {
- this.x = x;
- this.y = y;
- this.width = width;
- this.style = "move";
-
- this.lists = new Array(); // sublists
- this.items = new Array(); // layers
- this.types = new Array(); // type
-
- this.setStyle = setStyle //sets the style of the tree menu
- this.setImage = setImage //sets the open and close graphics
- this.addItem = addItem; //adds an item to the tree
- this.addList = addList; //adds a sublist to the tree
- this.build = build; //builds the menu
- this.switchIt = switchOpenClose; //opens or closes the menu
- this.switchMoveMenu = switchMenu //opens or closes submenu in move style
- this.switchCloseMenu = switchToggle //opens or close submenu in openclose style
- this.open = showSubMenu //opens the menu
- this.close = closeSubMenu //closes the menu
- this.closeAll = closeSubMenuToggle//closes the menu
- this.switchImage = switchImage //switches the image
- this.closeAllImages = closeImages //sets all images to default in that tree.
- }
-
-
- //this function sets the images to indicate open or close
- //parameters:
- // openimage - the image to be displayed when the menu is open.
- // closedimage - the image to be displayed when the menu is closed.
- //
- function setImage(openimage,closedimage)
- {
- closedImg.src = closedimage;
- openImg.src = openimage;
- }
-
-
-
-
- //this function sets the style of the tree menu i.e move/openclose
- //parameters:
- // style - type of tree menu
- //
- function setStyle(style)
- {
- this.style = style
- }
-
-
-
- //this function adds a layer to the root
- //parameters:
- // layername - nameof the div to pick up
- //
- function addItem(layername)
- {
- pos = this.items.length;
-
- //create an object
- this.items[pos] = new Object();
- this.types[pos] = "item";
-
- //set the properties for that object
- this.items[pos].open = false;
- this.items[pos].layername = layername;
-
- this.items[pos].link = new DynLayer(layername);
- this.items[pos].linkHeight = this.items[pos].link.getContentHeight();
-
- // Calculate The Postion For Each layer
- if (pos == 0)
- {
- this.items[pos].nextLink = this.y
- }
- else
- {
- this.items[pos].nextLink = this.items[pos-1].nextLink + this.items[pos-1].linkHeight
- }
-
- }
-
-
- //this function adds a layer to the root
- //parameters:
- // list - the sublist
- // layername - nameof the div to pick up
- //
- function addList(list,layername)
- {
- pos = this.items.length;
-
- //create an object
- this.lists[pos] = list;
- this.items[pos] = new Object();
- this.types[pos] = "list";
-
-
- //set the properties for that object
- this.items[pos].open = false
- this.items[pos].layername = layername;
-
- this.items[pos].link = new DynLayer(layername);
- this.items[pos].linkHeight = this.items[pos].link.getContentHeight();
-
- // Calculate The Postion For Each layer
- if (pos == 0)
- {
- this.items[pos].nextLink = this.y
- }
- else
- {
- this.items[pos].nextLink = this.items[pos-1].nextLink + this.items[pos-1].linkHeight
- }
-
- }
-
-
-
- //this function builds all the layers
- //parameters:
- //
- function build()
- {
- // Initialize totalHeightOfLayers To 0
- numBlocks = this.items.length;
- totalHeightOfLayers = 0;
-
- for (var i=0;i<numBlocks;i++)
- {
- // Calculate Total Height Of All Layers
- totalHeightOfLayers += this.items[i].linkHeight;
-
- // Move Each layerMenuLink Into Position
- if (i == 0)
- {
- this.items[i].link.moveTo(this.x,this.y);
- }
- else
- {
- this.items[i].link.moveTo(this.x,this.items[i].nextLink);
- }
-
- // Show Each layerMenuLink After They Are Moved Into Place
- this.items[i].link.show();
-
- }
-
- // Add totalHeightOfLayers To layerMenuBuffer To Deal With IE On Mac Problems
- if (is.ie)
- document.all.layerMenuBuffer.style.height = totalHeightOfLayers;
- }
-
-
-
- //this function opens or closes the menu
- //parameters:
- // layernum - name of the level to open
- //
- function switchOpenClose(layernum)
- {
- // Set Position Initially To Y Offset
- Position = this.y
- Level=0;
-
- //change the menu
- if(this.style == "move")
- this.switchMoveMenu('layer'+layernum);
- else
- {
- //window.scroll(0,0);
- this.switchCloseMenu('layer'+layernum);
- }
-
- //change the image
- this.switchImage(layernum);
-
- // Adjust Netscapes Document Size To Size Of Visible Layers
- // if (is.ns4) document.height = Position+this.items[0].linkHeight
-
-
- }
-
-
-
-
- function switchImage(layernum)
- {
-
- if (is.ns4)
- {
- if(eval('document.layer'+layernum+'.document.images["img'+layernum+'"]').src == openImg.src)
- {
- eval('document.layer'+layernum+'.document.images["img'+layernum+'"]').src = closedImg.src;
- }
- else
- {
- eval('document.layer'+layernum+'.document.images["img'+layernum+'"]').src = openImg.src;
- }
-
- }
- else
- {
- if(eval('document.images.img'+layernum).src == openImg.src)
- eval('document.images.img'+layernum).src = closedImg.src;
- else
- eval('document.images.img'+layernum).src = openImg.src;
- }
- }
-
-
-
- function closeImages()
- {
- var layer;
- for(var i=0; i<imgColl.length; i++)
- {
- layer = imgColl[i];
- this.switchImage(layer.substring(5,layer.length));
- }
- }
-
-
-
- function switchToggle(layername)
- {
- var numBlocks = this.items.length;
- var i = 0;
- for (i=0; i<numBlocks; i++ )
- {
- //check if its a list
- if(this.types[i] == "list")
- {
- //check if this is the layer
- if(this.items[i].layername == layername)
- {
- //show this link
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
- Found = true;
- if(this.items[i].open == false)
- {
- //open the layer if it is closed
- this.items[i].open = true;
- this.open(i);
- }
- else
- {
- //close the layer if it is open
- this.items[i].open = false;
- imgColl = new Array();
- this.closeAll(i);
- this.closeAllImages();
- }
- }
- else
- {
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
- if(Level == 0)
- LevelPos = Position;
- //check if it is open
- if(this.items[i].open == true)
- {
- Level=Level+1;
- this.lists[i].switchCloseMenu(layername);
- Level=Level-1;
- }
- }
-
- if(Level==0)
- {
- if(Found == false)
- {
- if(this.items[i].open == true)
- {
- this.items[i].open = false;
- imgColl = new Array();
- imgColl[imgColl.length] = this.items[i].layername;
- this.closeAll(i);
- this.closeAllImages();
- this.switchImage(i);
- Position = LevelPos;
- }
- }
-
- Found = false;
- }
-
- }
- else
- {
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
- }
-
- }
-
- }
-
-
-
-
-
- function switchMenu(layername)
- {
- var numBlocks = this.items.length;
- var i = 0;
- for (i=0; i<numBlocks; i++ )
- {
- //check if its a list
- if(this.types[i] == "list")
- {
- //check if this is the layer
- if(this.items[i].layername == layername)
- {
- //show this link
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
-
- if(this.items[i].open == false)
- {
- //open the layer if it is closed
- this.items[i].open = true;
- this.open(i);
- }
- else
- {
- //close the layer if it is open
- this.items[i].open = false;
- this.close(i);
- }
- }
- else
- {
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
-
- //check if it is open
- if(this.items[i].open == true)
- {
- this.lists[i].switchMoveMenu(layername);
- }
- }
-
- }
- else
- {
- this.items[i].link.moveTo(this.x,Position);
- Position = Position + this.items[i].linkHeight;
- }
-
- }
-
- }
-
-
- //this function opens the submenu
- //parameter:
- // i - current level
- function showSubMenu(i)
- {
- numBlocks = this.lists[i].items.length;
-
- for (subBlocks=0;subBlocks<numBlocks ; subBlocks++)
- {
- this.lists[i].items[subBlocks].link.moveTo(this.x,Position)
- Position = Position + this.lists[i].items[subBlocks].linkHeight;
- this.lists[i].items[subBlocks].link.show();
- }
-
- }
-
-
- //this function closes the submenu
- //parameter:
- // i - current level
- function closeSubMenu(i)
- {
- var numBlocks = this.lists[i].items.length;
- var subBlocks=0;
-
- for (subBlocks=0;subBlocks<numBlocks ; subBlocks++)
- {
- if(this.lists[i].types[subBlocks] == "list")
- this.lists[i].close(subBlocks);
- this.lists[i].items[subBlocks].link.hide();
- }
- }
-
-
- //this function closes the submenu in toggle mode
- //parameter:
- // i - current level
- function closeSubMenuToggle(i)
- {
- var numBlocks = this.lists[i].items.length;
- var subBlocks=0;
-
- for (subBlocks=0;subBlocks<numBlocks ; subBlocks++)
- {
- if(this.lists[i].types[subBlocks] == "list")
- {
- if(this.lists[i].items[subBlocks].open == true)
- {
- this.lists[i].items[subBlocks].open = false;
- imgColl[imgColl.length] = this.lists[i].items[subBlocks].layername;
- this.lists[i].closeAll(subBlocks);
- }
- }
- this.lists[i].items[subBlocks].link.hide();
-
- }
- }
-